package com.realdolmen.jcc.mobileSquad.domain
{
	/**
	 * Simple ActionScript domain object representing a Customer
	 * @author DOMSIEBE
	 */
	[Bindable]
	public class Customer {
		private static const DEFAULT_LOGO:String = "logo/default.png"; 
		
		public var id:Number;
		public var name:String;
		public var contact:Contact;
		public var address:Address;
		public var homePage:String;
		public var logo:String;
		
		/**
		 * The Customer constructor. 
		 * @param id The database id
		 * @param name The name of the customer
		 * @param logo A link to the company logo
		 * @param contact The contact person
		 * @param address The address
		 */		
		public function Customer(id:Number = NaN,
								 name:String = "",
								 contact:Contact = null, 
								 address:Address = null,
								 homePage:String="",
								 logo:String = DEFAULT_LOGO){
			this.id = id;
			this.name = name;
			if(contact){
				this.contact = contact;
			}else{
				this.contact = new Contact();
			}
			if(address){
				this.address = address;
			}else{
				this.address = new Address();
			}
			this.logo = logo;
			this.homePage = homePage;
		}
		
		/**
		 * Wrapper for city.
		 * If we don't write this getter we need to write a labelFuntion.
		 * @return the City
		 */ 
		public function get cityWrapper():String{
			return address.city;
		}
		
		/**
		 * Build a customer from a database row object
		 * @param row The database row.
		 * @return A customer object.
		 */		
		public static function buildCustomer(row:Object):Customer{
			var contact:Contact = new Contact(row.contactFirstName, row.contactLastName, row.contactPhone, row.contactEmail, row.contactPhoto);
			var address:Address = new Address(row.companyStreet, row.companyCity, row.companyLongitude, row.companyLatitude);
			var customer:Customer = new Customer(row.id, row.companyName, contact, address, row.companyHomePage, row.companyLogo);
			return customer;
		}
	}
}